package com.tanhua.dubbo.server.HtMessageApi;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.api.QuanZiApi;
import com.tanhua.dubbo.server.pojo.Comment;
import com.tanhua.dubbo.server.vo.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.List;

@Service(version = "1.0.0")
@Slf4j
public class MessageListApiImpl implements MessageListApi {
    @Autowired
    MongoTemplate mongoTemplate;
    @Autowired
    private QuanZiApi quanZiApi;


    /**
     * 根据消息id获取所有的评论对象
     *
     * @param page
     * @param pageSize
     * @param sortProp
     * @param sortOrder
     * @param messageId
     * @return
     */
    @Override
    public PageInfo<Comment> getCommentLists(Integer page, Integer pageSize, String sortProp, String sortOrder, String messageId) {
        //创建结果集对象
        PageInfo<Comment> pageInfo = new PageInfo<>();
        pageInfo.setPageSize(pageSize);
        pageInfo.setPageNum(page);
        /*PageRequest pageRequest = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc("created")));
        Query query = Query.query(Criteria.where("publishId").is(new ObjectId(messageId))).with(pageRequest);
        List<Comment> comments = mongoTemplate.find(query, Comment.class);*/

        //按条件查询所有的评论
        List<Comment> comments = quanZiApi.findAllComments(page, pageSize, messageId);

        pageInfo.setTotal(comments.size());
        pageInfo.setRecords(comments);

        return pageInfo;
    }
}
